/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package giuliani_mapelli_marocco.security;

import giuliani_mapelli_marocco.business.UserManager;
import giuliani_mapelli_marocco.business.EventManager;
import giuliani_mapelli_marocco.entity.Event;
import giuliani_mapelli_marocco.entity.User;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.EJBException;
import javax.inject.Named;
import javax.enterprise.context.RequestScoped;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

@Named
@RequestScoped
public class UserBean {

    @EJB
    UserManager um;
    
    @EJB
    EventManager em;
    
    private String username;

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }
    
    public UserBean() {
    }
    
    public User getLoggedUser() {
        return um.getLoggedUser();
    }
    
    public String getMyEvent() {
        List<Event> events=  em.getAllUserEvent(um.getLoggedUser().getUsername());
        String eventString="";
        for (Event e: events) {
            eventString= eventString+e.toString();
        }
        return eventString;
    }
    
    public String getCalendarVisibility() {
        if(um.getLoggedUser().getCalendarPublic()) {
            return "PUBLIC";
        }
            return "PRIVATE";
    }
    
    public void changeCalendarVisibility() {
       um.changeVisibility(um.getLoggedUser());
       
    }

}